import logging
import allure
import jsonpath

from utils.send_request import send_jdbc_request


def json_extractor(case,all,res):
    if case['jsonExdata']:
        with allure.step("5.json提取"):
            for key, value in eval(case['jsonExdata']).items():
                value = jsonpath.jsonpath(res.json(), value)[0]
                all[key] = value
            # JSON提取信息日志
            logging.info(f"4.JSON数据提取，根据（{case['jsonExdata']}）提取数据,此时全局变量为:{all}")


def jdbc_extractor(case,all):
    if case['sqlExdata']:
        with allure.step("5.JDBC提取"):
            for key, value in eval(case['sqlExdata']).items():
                value = send_jdbc_request(value)
                all[key] = value
            # JDBC提取信息日志
            logging.info(f"4.JDBC数据提取，根据（{case['sqlExdata']}）提取数据,此时全局变量为:{all}")